<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            变化点发起
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:60px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">大类</div>
                    <div class="aui-list-item-input">
                        <select id="classFlag">
                        </select>
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">变化点分类</div>
                    <div class="aui-list-item-input">
                        <select id="pointClass" onchange="onChange()">
                        </select>
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">变化内容</div>
                    <div class="aui-list-item-input">
                        <select id="pointOfChangeId">
                        </select>
                    </div>
                </div>
            </li>
            <li class="aui-list-item" style="display:none">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">产线id</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="workCenterGid">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">生产线编码</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="选择生产线" id="workCenterCode" value="" disabled="true"
                            onclick="getIdSelector();" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectWorkCenter()"></i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">生产线名称</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="workCenterName" disabled="true">
                    </div>
                </div>
            </li>
            <li class="aui-list-item" style="display:none">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">工序id</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="opId">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">工序编码</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="选择工序" id="opCode" value="" disabled="true"
                            onclick="getIdSelector();" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectOp()"></i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">工序名称</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="opName" disabled="true">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">物料编码</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="选择物料" id="mrlCode" value="" disabled="true"
                            onclick="getIdSelector();" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectMrl()"></i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">物料名称</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="mrlName" disabled="true">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">设备编码</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="选择设备" id="equipCode" value="" disabled="true"
                            onclick="getIdSelector();" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectEquip()"></i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">设备名称</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="equipName" disabled="true">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">备注</div>
                    <div class="aui-list-item-input">
                        <textarea id="remark"></textarea>
                    </div>
                </div>
            </li>
        </ul>
    </div>

    <div class='aui-btn aui-btn-info aui-btn-block' style="margin-top:10px;" onclick='save()'>发起</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    apiready = function () {

        //查询大类
        getCombox("pointBigClass");

        //查蓄奴变化点类别下拉框
        getCombox("pointClass");
    };

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        $("#" + el.id).select();
    }
    //选择生产线
    function goSelectWorkCenter() {
        api.openWin({
            name: 'uwmWorkCenter',
            url: 'uwmWorkCenter.html',
            pageParam: {
                flag: "in",
                name: "qcPointChangeBill",
                mrlCode: "",
                lotCode: "",
                qty: ""
            }
        });
    }

    //生产线选择后回调函数
    function setWorkCenter(id, code, name) {
        $("#workCenterGid").val(id);
        $("#workCenterCode").val(code);
        $("#workCenterName").val(name);
        $("#workCellCode").focus();
    }

    //查询下拉框
    function getCombox(id) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getUtilComboxList";
        var data = {
            values: {
                tablename: "md_paraconfig",
                column_name: "paracode",
                column_value: "paraval",
                condition: "paracls = '" + id + "' and is_delete=0",
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                }
                if (id == "pointBigClass") {
                    $api.html($api.byId("classFlag"), html);
                } else if (id == "pointClass") {
                    $api.html($api.byId("pointClass"), html);
                }
            }
        });
    }

    //变化点分类值改变
    function onChange() {
        var un = localStorage.getItem('un');
        var classFlag = $("#classFlag").val();
        var pointClass = $("#pointClass").val();
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getUtilComboxList";
        var data = {
            values: {
                tablename: "qc_point_of_change_class",
                column_name: "content",
                column_value: "sysid",
                condition: "class_flag = '" + classFlag + "' and point_class = '" + pointClass + "'",
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                }
                $api.html($api.byId("pointOfChangeId"), html);
            }
        });
    }

    //选择工序
    function goSelectOp() {
        api.openWin({
            name: 'usmSelectOp',
            url: 'usmSelectOp.html',
            pageParam: {
                name: "qcPointChangeBill",
            }
        });
    }

    //工序选择后回调函数
    function setOp(sysid, code, name) {
        $("#opId").val(sysid);
        $("#opCode").val(code);
        $("#opName").val(name);

    }

    //选择物料
    function goSelectMrl() {
        api.openWin({
            name: 'usmSelectMrl',
            url: 'usmSelectMrl.html',
            pageParam: {
                name: "qcPointChangeBill",
            }
        });
    }

    //物料选择后回调函数
    function setMrl(sysid, code, name) {
        $("#mrlCode").val(code);
        $("#mrlName").val(name);

    }

    //选择设备
    function goSelectEquip() {
        api.openWin({
            name: 'mdSelectEquip',
            url: 'mdSelectEquip.html',
            pageParam: {
                name: "qcPointChangeBill",
            }
        });
    }

    //设备选择后回调函数
    function setEquip(sysid, code, name) {
        $("#equipCode").val(code);
        $("#equipName").val(name);

    }

    //发起保存
    function save() {
        //变化内容
        var pointOfChangeId = $("#pointOfChangeId").val();
        //工序id
        var opId = $("#opId").val();
        //工序编码
        var opCode = $("#opCode").val();
        //工序名称
        var opName = $("#opName").val();
        //物料编码
        var mrlCode = $("#mrlCode").val();
        //物料名称
        var mrlName = $("#mrlName").val();
        //设备编码
        var equipCode = $("#equipCode").val();
        //设备名称
        var equipName = $("#equipName").val();
        //备注
        var remark = $("#remark").val();
        //生产线编码
        var workCenterCode = $("#workCenterCode").val();
        //生产线名称
        var workCenterName = $("#workCenterName").val();
        //生产线id
        var workCenterGid = $("#workCenterGid").val();

        //变化内容非空校验
        if (pointOfChangeId == "" || pointOfChangeId == null || pointOfChangeId == undefined) {
            api.toast({
                msg: '变化内容不能为空',
                duration: 3000
            });
            return;
        }

        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/qcPointChangeSave";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                pointOfChangeId: pointOfChangeId,
                opId: opId,
                opCode: opCode,
                opName: opName,
                mrlCode: mrlCode,
                mrlName: mrlName,
                equipCode: equipCode,
                equipName: equipName,
                remark: remark,
                workCenterCode: workCenterCode,
                workCenterName: workCenterName,
                workCenterGid: workCenterGid,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {

                    api.hideProgress();
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });

                    //清空表单
                    reset();
                } else if (myobj.code == '1') {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
                alert(JSON.stringify(err));
            }
        });
    }


    //清空
    function reset() {
        $api.html($api.byId("classFlag"), "");
        $api.html($api.byId("pointClass"), "");
        $api.html($api.byId("pointOfChangeId"), "");
        $("#opId").val("");
        $("#opCode").val("");
        $("#opName").val("");
        $("#mrlCode").val("");
        $("#mrlName").val("");
        $("#equipCode").val("");
        $("#equipName").val("");
        $("#remark").val("");
        $("#workCenterCode").val("");
        $("#workCenterName").val("");
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>